<template>
  <common_print_dialog ref="common_print_dialog" :businessType="businessType" v-bind="$attrs" v-on="$listeners"
    :printUrl="printUrl" :printHandler="printHandler" :previewUrl="previewUrl" :previewHandler="previewHandler"
    :previewMergeUrl="previewMergeUrl" :previewMergeHandler="previewMergeHandler" />
</template>

<script>
import common_print_dialog from './common_print_dialog.vue'

export default {
  components: { common_print_dialog },
  data() {
    return {
      printUrl: "/print-api/template/PrintRpc/print.json",
      previewUrl: "/print-api/template/PrintRpc/previewPrintBase.json",
      previewMergeUrl: "/print-api/template/PrintRpc/mergePdf.json",
    }
  },
  props: {
    businessType: {
      type: String,
      default: ''
    },
    metaHandler: Function,
  },
  methods: {
    previewMergeHandler(data, rows) {
      data.metadataList = rows.map(it => (this.metaHandler(data, it)));
      return data
    },
    printHandler(data, rows) {
      data.metaDataList = rows.map(it => ({
        metadata: this.metaHandler(data, it),
        printNum: it.printNum,
      }));
      return data
    },
    previewHandler(data, row) {
      data.metadata = JSON.stringify(this.metaHandler(data, row));
      return data
    },
    show(rows,option) {
      this.$refs.common_print_dialog.show(rows,option)
    },

    printDefaultOption(option){
      this.$refs.common_print_dialog.printDefaultOption(option)
    }

  }
}
</script>
